<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Document</title>
  <style>
    .abc {
      width: 200px;
      height: 200px;
      border: 1px solid #000;
    }
    .bg-red {
      background-color: red;
    }
  </style>
</head>
<body>
  <input type="button" id="btn" value="添加类名到box里面">
  <div id="box" class="abc"></div>
</body>
<script>
var box1=document.getElementById('btn');
var box2=document.getElementById('box');
box1.onclick=function(){
  console.log(box2.id);
  console.log(box2.className);
  box2.className='bg-red';
}

</script>
</html>